package com.atguigu.lease.admin.service.impl;

import com.atguigu.lease.admin.service.*;
import com.atguigu.lease.model.vo.lease.AggrementItemVo;
import com.atguigu.lease.model.vo.lease.AggrementQueryVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.lease.model.bean.LeaseAgreement;
import com.atguigu.lease.admin.mapper.LeaseAgreementMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author 1
* @description 针对表【lease_agreement(租约信息表)】的数据库操作Service实现
* @createDate 2025-06-20 14:04:43
*/
@Service
public class LeaseAgreementServiceImpl extends ServiceImpl<LeaseAgreementMapper, LeaseAgreement>
    implements LeaseAgreementService{
    @Autowired
    private ApartmentInfoService apartmentInfoService;
    @Autowired
    private RoomInfoService roomInfoService;
    @Autowired
    private PaymentTypeService paymentTypeService;
    @Autowired
    private LeaseTermService leaseTermService;
    @Override
    public Page<AggrementItemVo> pageItem(Long current, Long size, AggrementQueryVo aggrementQueryVo) {
        return baseMapper.selectAggrementItemVoPage(new Page<AggrementItemVo>(current,size),
                aggrementQueryVo);
    }

    @Override
    public AggrementItemVo getAggrementItemVo(Long id) {
        AggrementItemVo vo = new AggrementItemVo();
        //1、查询并设置租约信息
        LeaseAgreement leaseAgreement = this.getById(id);
        BeanUtils.copyProperties(leaseAgreement,vo);
        //2、查询并设置公寓信息
        vo.setApartmentInfo(apartmentInfoService.getById(leaseAgreement.getApartmentId()));
        //3、查询并设置房间信息
        vo.setRoomInfo(roomInfoService.getById(leaseAgreement.getRoomId()));
        //4、查询并设置支付方式信息
        vo.setPaymentType(paymentTypeService.getById(leaseAgreement.getPaymentTypeId()));
        //5、查询并设置租期信息
        vo.setLeaseTerm(leaseTermService.getById(leaseAgreement.getLeaseTermId()));
        return vo;
    }
}




